package org.seven.jrdp.commons.shiro.authc;

import java.util.Collection;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.pam.ModularRealmAuthenticator;
import org.apache.shiro.realm.Realm;

public class UserAuthenticator extends ModularRealmAuthenticator {
	@Override
	protected AuthenticationInfo doAuthenticate(AuthenticationToken authenticationToken) throws AuthenticationException {
		UserToken userToken = (UserToken) authenticationToken;
		Collection<Realm> realms = getRealms();
		for (Realm realm : realms) {
			if (realm.getName().equals(userToken.getUserType().toString())) {
				return doSingleRealmAuthentication(realm, userToken);
			}
		}
		return null;
	}
}